public class 最大差值 {
    /**
     * https://www.nowcoder.com/practice/a01abbdc52ba4d5f8777fb5dae91b204?tpId=182&tqId=34396&rp=1&ru=/exam/oj&qru=/exam/oj&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D182&difficulty=2&judgeStatus=undefined&tags=&title=
     * 贪心思想
     */

    public int getDis (int[] A, int n) {
        int aMin = A[0];//标记每次遍历i前的最小值

        int ans = 0;//返回值
        for(int i = 1;i < n;i++){
            //不断更新最小值和ans
            aMin = Math.min(aMin,A[i]);
            ans = Math.max(ans,A[i] - aMin);
        }
        return ans;
    }
}
